// index.js
// 获取应用实例
const app = getApp()

Page({
  // 微信小程序轮播图
  data: {
    
    background: ['demo-text-1', 'demo-text-2', 'demo-text-3'],
    indicatorDots: true,
    vertical: false,
    autoplay:true,
    interval: 5000,
    duration: 500,
    //轮播图
    banners: [{
      id: 1,
      image: '/image/a1.png',
      // path:''
    },
    {
      id: 2,
      image: '/image/a2.png',
      // path:''
    },
    {
      id: 3,
      image: '/image/a3.png',
      // path:''
    },
    {
      id: 4,
      image: '/image/a4.png',
      // path:''
    }
    ],
    news:[],
    newsIndex:0,
    newItems:'transform: translate(0rpx,0rpx); transition:transform 0.3s;',
  },
 
//新闻轮播
  getNews(){
    let timer = setTimeout(()=>{
      let news = [
        {
          id:1,         
          title:'典雅新中式，极致的东方惊艳'
        },
        {
          id:2,    
          title:'新品首晒，限时折扣'
        },
        {
          id:3,
          title:'设计严选，严控出品'
        },
        {
          id:4,        
          title:'精品高端定制'
        },
        {
          id:5,         
          title:'welcome 聚造商城'
        }
      ]
      this.setData({
        news
      })
    },5000)
  },
  changNewsIndex(){  //新闻轮播没5秒跳转一次
    setInterval(()=>{
      let newsIndex = this.data.newsIndex
      newsIndex ++
      console.log(this.data.news)
      if(newsIndex == this.data.news.length)newsIndex = 0 
      console.log('这是第几条',newsIndex)
      this.setData({
        newsIndex,
        newItems:'transform:translate(0rpx,-'+newsIndex*80+'rpx);transition:transform=1s;'
      })
    },5000)
  },
  onLoad() {
    if (wx.getUserProfile) {
      this.setData({
        canIUseGetUserProfile: true
      })
    }
    this.getNews()//获取新闻
    this.changNewsIndex() //触发新闻轮播
  },

  //点击事件
  tapNews() {
    wx.navigateTo({
      url: '/pages/boxs/news/news',
    })
  },
  tapHigh() {
    wx.navigateTo({
      url: '/pages/boxs/high/high',
    })
  },
  tapVip() {
    wx.navigateTo({
      url: '/pages/boxs/vip/vip',
    })
  },
  tapAll() {
    wx.navigateTo({
      url: '/pages/boxs/all/all',
    })
  },
  tapSell() {
    wx.navigateTo({
      url: '/pages/detail/sell/sell',
    })
  },
  tapBrand() {
    wx.navigateTo({
      url: '/pages/detail/brand/brand',
    })
  },
  onPullDownRefresh() {
    wx.startPullDownRefresh()
    console.log('刷新成功')
  },
  
  onPullDownRefresh() {
    wx.startPullDownRefresh()
    console.log('刷新成功')
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  

})
